//###############
// FILE : SetupTab.java
// WRITER : Lior Zimmerman liorz06 066462300
// WRITER : Ohad Dan ohad_dan 036767960
// EXERCISE : oop ex3 2008
// DESCRIPTION:
//  Representation of the SetUp tab.
//###############

package oop.ex3.fileSearchView;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

import oop.ex3.fileSearchController.CanRunAction;
import oop.ex3.fileSearchController.SelectOutputFileAction;
import oop.ex3.fileSearchController.SetupOutputAction;
/**
 * Representation of the SetUp tab.
 */
public class SetupTab extends GUITab implements SetupTabInterface{
    private static final long serialVersionUID = 1L;

	//********************************************************************
	//  Data members :                                                   *
	//********************************************************************
    private GridBagConstraints _layoutBag;
    private JRadioButton _radioBtnPrintToFile;
    private JRadioButton _radioBtnPrintScreen;
    private JRadioButton _radioBtnScreenFile;
    private JButton _btnOutputFile;
    private JTextField _txtOutputFile;
	//********************************************************************
	//  Finals :                                                         *
	//********************************************************************
	private final String PRNT_TO_FILE_TITLE = "Print to file";
	private final String PRNT_TO_SCRN_TITLE = "Print to Screen";
	private final String PRNT_TO_SCRN_FILE_TITLE = 
		"Print to screen and file";
	private final String BTN_OUTPUT_FILE_TXT = "Output file";
	private final String TAB_TITLE = "Setup Dialog";

	//********************************************************************
	//  Methods :                                                        *
	//********************************************************************	
    /**
     * Construct a new Setup tab.
     * @param gui The main frame.
     */
	public SetupTab( GUIInitializer gui ){ 
        super(gui);
        setLayout( new GridBagLayout() );
        
        //Create Tab components.
        _layoutBag = new GridBagConstraints();
        _radioBtnPrintToFile = new JRadioButton(PRNT_TO_FILE_TITLE);
        _radioBtnPrintScreen = new JRadioButton(PRNT_TO_SCRN_TITLE);
        _radioBtnScreenFile = new JRadioButton( PRNT_TO_SCRN_FILE_TITLE);
        _radioBtnPrintScreen.setSelected(true);
        _btnOutputFile = new JButton(BTN_OUTPUT_FILE_TXT);
        _txtOutputFile = new JTextField();
        _btnOutputFile.setEnabled(false);
        _txtOutputFile.setEnabled(false);
        //add radio buttons to a group
        ButtonGroup groupBtnFilter = new ButtonGroup();        
        groupBtnFilter.add(_radioBtnPrintScreen);
        groupBtnFilter.add(_radioBtnPrintToFile);
        groupBtnFilter.add(_radioBtnScreenFile);        
        setBorder( BorderFactory.createTitledBorder(TAB_TITLE) );
        
        //Put all component in grid.
        _layoutBag.gridx=0;
        _layoutBag.gridy=0;
        _layoutBag.anchor = GridBagConstraints.WEST;
        add(_radioBtnPrintToFile,_layoutBag);
        _layoutBag.gridx=0;
        _layoutBag.gridy=1;
        add(_radioBtnPrintScreen,_layoutBag);
        _layoutBag.gridx=0;
        _layoutBag.gridy=2;
        add(_radioBtnScreenFile,_layoutBag);
        _layoutBag.gridx=0;
        _layoutBag.gridy=3;
        _layoutBag.fill = GridBagConstraints.HORIZONTAL;
        add(_btnOutputFile,_layoutBag);
        _layoutBag.gridx=0;
        _layoutBag.gridy=4;
        _layoutBag.fill = GridBagConstraints.HORIZONTAL;
        add(_txtOutputFile,_layoutBag);   
        
    }

    /**
     * Sets listeners for all tab components. 
     */
    public void setActionListeners() {
        _btnOutputFile.addActionListener(new 
                SelectOutputFileAction(_guiPointer));
        _radioBtnPrintScreen.addActionListener(new 
                SetupOutputAction(_guiPointer));
        _radioBtnPrintToFile.addActionListener(new 
                SetupOutputAction(_guiPointer));
        _radioBtnScreenFile.addActionListener(new 
                SetupOutputAction(_guiPointer));
        _txtOutputFile.getDocument().addDocumentListener
        (new CanRunAction(_guiPointer));
    }     
    /**
	 * Sets the print to file button enabled.
	 * @param status Button status.
	 */
	public void setButtonPrintToFile(boolean status){
		_radioBtnPrintToFile.setEnabled(status);
	}
	/**
	 * Sets the print to screen button enabled.
	 * @param status Button status.
	 */
	public void setButtonPrintToScreen(boolean status){
		_radioBtnPrintScreen.setEnabled(status);
	}
	/**
	 * Sets the print to screen and file button enabled.
	 * @param status Button status.
	 */
	public void setButtonPrintToScreenFile(boolean status){
		_radioBtnScreenFile.setEnabled(status);
	}
	/**
	 * Sets the text at the text output field.
	 * @param str Text to be set.
	 */
	public void setTextOutputFile(String str){
		_txtOutputFile.setText(str);
	}
	
	/**
	 * Sets the output file button .
	 */
	public void setButtonOutputFile(boolean status){
		_btnOutputFile.setEnabled(status);
	}
	/**
	 * Return the status of the button.
	 * @return True if the button is selected, false otherwise.
	 */
	public boolean rdoToFileSelected(){
		return _radioBtnPrintToFile.isSelected();
	}
	/**
	 * Return the status of the button.
	 * @return True if the button is selected, false otherwise.
	 */
	public boolean rdoToScreenSelected(){
		return _radioBtnPrintScreen.isSelected();
	}
	/**
	 * Return the status of the button.
	 * @return True if the button is selected, false otherwise.
	 */
	public boolean rdoToFileScreenSelected(){
		return _radioBtnScreenFile.isSelected();
	}
	/**
	 * Returns output text button text.
	 * @return Output button text.
	 */
	public String txtGetOutput(){
	    return _txtOutputFile.getText();
	}
	/**
	 * Sets the output text button status.
	 * @param val Button status.
	 */
	public void txtOutputSetEnabled( boolean val ){
	    _txtOutputFile.setEnabled(val);
	}
	/**
	 * Sets the To-file button status.
	 * @param val Button status.
	 */
   public void rdoSetSelectedToFile(boolean val){
       _radioBtnPrintToFile.setSelected(val);
   }
	/**
	 * Sets the To-file-&-Screen button status.
	 * @param val Button status
	 */
   public void rdoSetSelectedToFileScreen(boolean val){
       _radioBtnScreenFile.setSelected(val);
   }
   /**
	 * Sets the To-Screen button status.
	 * @param val Button status
	 */
   public void rdoSetSelectedToScreen(boolean val){
       _radioBtnPrintScreen.setSelected(val);
   }

}
